<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加公告</title>

    <meta name="pragma" content="no-cache">
    <meta name="cache-control" content="no-cache">
    <meta name="content-type" content="text/html;charset=UTF-8">
    <meta name="expires" content="0">
    <div th:replace="~{commons/script::script}"></div>

</head>

<style type="text/css">
    .myselect{
        height:30px;
        width:80%;

    }
</style>

<body style="width:100%;max-width:600px;padding:10px 30px;">
<form id="form" method="post">
    <strong>基本信息</strong>

    <section class="info-section">

        <table id="tb">
            <tr>
                <td class="text-title"> 标题：</td>
                <td>
                    <input type="text" style="width:80%;" name="title" class="easyui-textbox theme-textbox-radius" >
                </td>
            </tr>
            <tr>
                <td class="text-title"> 颜色：</td>
                <td>
                    <input type="text" style="width:80%;" name="color" class="easyui-textbox theme-textbox-radius" >

                </td>
            </tr>
            <tr>
                <td class="text-title"> 排序编号：</td>
                <td>

                    <input type="text" style="width:80%;" name="orderId" class="easyui-textbox theme-textbox-radius" >
                </td>
            </tr>
            <tr>
                <td class="text-title"> 是否显示：</td>
                <td>
                    <input type="radio" name="isshow" checked value="1" />是
                    <input type="radio" name="isshow"  value="0" />否
                </td>
            </tr>
            <tr>
                <td class="text-title">  是否发布：</td>
                <td>
                    <input type="radio" name="status" checked value="1" />是
                    <input type="radio" name="status" value="0" />否
                </td>
            </tr>
            <tr>
                <td class="text-title">通知部门：</td>
                <td class="text-content">
                    <select  class="myselect" name="department">
                        <option value="-1">请选择部门</option>
                        <option th:each="depart:${departments}" th:value="${depart.id}" th:text="${depart.name}"></option>
                    </select>
                </td>

            </tr>
            <tr>
                <td class="text-title">内容</td>
                <td class="text-content">
                    <textarea name="content" rows="10" style="width:80%;"></textarea>
                </td>
            </tr>


            <tr>
                <td colspan="2" style="text-align: center;margin-top: 10px;">
                    <a href="javascript:void(0);" id="saveBtn" class="easyui-linkbutton button-primary">保存</a>
                    <a href="javascript:void(0);" id="resetBtn" class="easyui-linkbutton button-danger">重置</a>
                </td>
            </tr>

        </table>
    </section>
</form>

<script type="text/javascript">
    $(function() {
        //重置按钮
        $("#resetBtn").on("click",function(event){
            $("#form").form("reset");
        });

        //为保存按钮添加事件
        $("#saveBtn").on("click",function(event){
            $("#form").form("submit",{
                url:"/announcement/addAnnouncement",
                onSumbit : function(){
                    //调用easyui中form对象的validate方法对表单中数据进行校验，该方法返回boolean值，如果为false会阻止表单提交
                    return $("#form").form("validate");
                },
                success : function(data){
                    var obj = eval("("+data+")");
                    if(obj.success){
                        $.messager.alert("提示",obj.message);
                        parent.closeTopWindow();
                    }else{
                        $.messager.alert("警告",obj.message);
                    }
                }
            });
        });

    });
    //给部门添加下拉框选项
    $(function() {
        $.post(
            "manage/position/Department_findAll.do",
            function(data){
                if(data){
                    var departmentId = "${announcementVO.departmentid}";
                    $.each(data.data,function(index,obj){
                        var option = $("<option"+" "+ "value="+obj.departmentid+">"+obj.name+"</option>");
                        if(departmentId && departmentId == obj.departmentid){
                            option.attr("selected",true);
                        }
                        $("select[name='departmentid']").append(option);
                    })
                }
            },"json"
        )
    });
</script>
</body>
</html>

